package com.wondersgroup.fjzlpt.org.dao.impl.jgqy.blxx;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.repository.sql.bean.SQLBean;
import com.quick.framework.boot.repository.sql.bean.page.PageQuerySQLBean;
import com.quick.framework.boot.repository.sql.bean.table.TableBean;
import com.quick.framework.boot.repository.sql.jdbcTemplate.impl.BaseJTDAOImpl;
import com.quick.framework.boot.repository.sql.jdbcTemplate.rs.ResultHandlerConstant;
import com.wondersgroup.fjzlpt.org.dao.inter.jgqy.blxx.BlxxDAO;
@Repository
public class BlxxDAOImpl extends BaseJTDAOImpl implements BlxxDAO{
	@Override
	@Autowired
	@Qualifier("TB_JGQY_BLXX")
	public void setTb(TableBean tb) {
		super.setTb(tb);
	}

	/**
	 * 分页查询
	 */
	public JSONObject queryPage(Map<String, String> map) {
		StringBuffer sbuf = new StringBuffer("select a.*, ");
		sbuf.append("(select XMMC from TB_ZY_XB where XMDM = a.XB) XBMC,");
		sbuf.append("(select XMMC from TB_ZY_HYZK where XMDM = a.HYZK) HYZKMC,");
		sbuf.append("(select XMMC from TB_ZY_MZ where XMDM = a.MZ) MZMC,");
		sbuf.append("(select YLJGMC from TB_ZD_YLJGXX where PTJGID = a.JZJG) JZJGMC,");
		sbuf.append("(select KSMC from TB_ZD_KSXX where PTJGID = a.JZJG and  KSDM = a.JZKS) JZKSMC,");
		sbuf.append("(select XM from TB_ZD_YLJGRYXX where PTJGID = a.JZJG and  KSDM = a.JZKS and YSGH = a.JZYS) JZYSXM ");
		sbuf.append(" from  "+this.tb.getTableName()+" a where 1=1 ");
		List list = new ArrayList();
		String value = map.get("HZXM");
		if(!StringUtils.isEmpty(value))
		{
			sbuf.append(" and a.HZXM like ? ");
			list.add("%"+value+"%");
		}
		value = map.get("ZDMC");
		if(!StringUtils.isEmpty(value))
		{
			sbuf.append(" and a.ZDMC like ? ");
			list.add("%"+value+"%");
		}
		value = map.get("JZJG");
		if(!StringUtils.isEmpty(value))
		{
			sbuf.append(" and a.JZJG = ? ");
			list.add(value);
		}
		value = map.get("BLID");
		if(!StringUtils.isEmpty(value))
		{
			sbuf.append(" and a.BLID = ? ");
			list.add(value);
		}
		PageQuerySQLBean sb = super.checkAndCreatePageQuerySQLBean(map, sbuf.toString(), "order by JZRQ,BLID DESC", list.toArray());
		return super.queryPage(sb, ResultHandlerConstant.JSONARRAY);
	}
}
